<template>
  <div class="content">
    <!-- 头部标签 -->
    <div class="top">
      <div class="T-left">
        <svg class="icon" aria-hidden="true">
          <use xlink:href="#icon-bofang"></use>
        </svg>
        <span>播放全部</span>
        <span class="total">(共{{ itemList.length }}首)</span>
      </div>
      <div class="T-right">
        <svg class="icon" aria-hidden="true">
          <use xlink:href="#icon-jiahao1"></use>
        </svg>
        收藏({{ changeCount(subscribedCount) }})
      </div>
    </div>
    <!-- 歌曲信息 -->
    <div class="message">
      <div
        class="message-item"
        v-for="(item, index) in itemList"
        :key="item.id"
      >
        <div class="message-left" @click="playMusic(index)">
          <span>{{ index + 1 }}</span>
          <div class="works">
            <p>{{ item.name }}</p>
            <div class="limitauthor">
              <span
                class="author"
                v-for="(item1, index) in item.ar"
                :key="index"
                >{{ item1.name }}</span
              >
            </div>
          </div>
        </div>
        <div class="message-right">
          <svg class="icon" aria-hidden="true">
            <use xlink:href="#icon-31liebiao"></use>
          </svg>
          <svg class="icon" aria-hidden="true" v-if="item.mv">
            <use xlink:href="#icon-shipin"></use>
          </svg>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { mapMutations } from "vuex";
export default {
  setup(props) {
    // console.log(props);
    function changeCount(num) {
      if (num >= 100000000) {
        return (num / 100000000).toFixed(1) + "亿";
      } else if (num >= 10000) {
        return (num / 10000).toFixed(1) + "W";
      }
    }
    return { changeCount };
  },
  props: ["itemList", "subscribedCount"],
  methods: {
    playMusic(i) {
      this.updateplayList(this.itemList);
      this.updateplayListIndex(i);
    },
    ...mapMutations(["updateplayList", "updateplayListIndex"]),
  },
};
</script>

<style lang="less" scoped>
.content {
  padding: 0.2rem;
  border-radius: 20px 20px 0 0;
  background-color: #fff;
  margin-top: 20px;
  .top {
    width: 100%;
    height: 1rem;

    display: flex;
    justify-content: space-between;
    .T-left {
      width: 4rem;
      font-size: 18px;
      font-weight: 400;
      height: 0.6rem;
      display: flex;
      align-items: flex-end;
      .icon {
        margin-right: 20px;
      }
      .total {
        font-size: 12px;
        color: grey;
      }
    }
    .T-right {
      width: 120px;
      height: 40px;
      background-color: red;
      border-radius: 20px;
      padding: 0 0 0 10px;
      display: flex;
      align-items: center;
      font-size: 12px;
      color: #fff;
      .icon {
        fill: #fff;
        width: 20px;
        height: 20px;
      }
    }
  }
  .message {
    .message-item {
      height: 1rem;
      width: 100%;
      // border: 1px solid;
      display: flex;
      .message-left {
        width: 80%;
        display: flex;
        align-items: center;
        .works {
          margin-left: 0.2rem;
          p {
            font-size: 0.32rem;
            font-weight: 600;
            width: 4rem;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
          }
          .limitauthor {
            width: 2rem;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;

            .author {
              font-size: 0.28rem;
              color: gray;
              margin-right: 0.1rem;
            }
          }
        }
      }
      .message-right {
        width: 20%;
        display: flex;
        align-items: center;
        flex-direction: row-reverse;
        justify-content: space-between;
        padding-left: .3rem;
        .icon {
          fill: gray;
          width: 0.4rem;
          height: 0.4rem;
        }
      }
    }
  }
}
</style>